package com.xmhmyh.generalframework.common.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.xmhmyh.generalframework.common.constants.Constants;
import com.xmhmyh.generalframework.common.enums.Symbol;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 于丁
 * @Description: 前端查找列表传过来的参数
 * @DateTime: 2020/7/29 6:48 下午
 * @Params:
 * @Return
 */
@Data
public class DataGridRequest implements Serializable {
    private static final long serialVersionUID = 1428900571855677329L;

    private long pageNo;

    private long pageSize;

    private String sortName;

    private String sortOrder;

    private List<Condition> conditions = Lists.newArrayList();
    public Map<String, LinkedHashMap<String, String>> getOrderClauseMap() {
        Map<String, LinkedHashMap<String, String>> orderClauseMap = Maps.newHashMap();
        if (StringUtils.isNotBlank(getSortName())) {
            LinkedHashMap<String, String> sortColumnMap = Maps.newLinkedHashMap();
            String[] sortNames = sortName.split(Symbol.COLON.getLabel());
            String[] sortOrders = sortOrder.split(Symbol.COLON.getLabel());
            for (int i = 0; i < sortNames.length; i++) {
                String sn = sortNames[i].trim();
                String so = sortOrders[i].trim();
                sortColumnMap.put(sn, so);
            }
            orderClauseMap.put(Constants.ORDERMAP, sortColumnMap);
        }
        return orderClauseMap;
    }
}
